package com.youmans.eduservice.controller;


import com.youmans.commonutils.R;
import com.youmans.eduservice.entity.EduChapter;
import com.youmans.eduservice.entity.chapter.ChapterVo;
import com.youmans.eduservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Youmans
 * @since 2022-05-07
 */
@RestController
@Api(tags = "章节控制器")
@RequestMapping("/eduservice/chapter")
public class EduChapterController {
    @Autowired
    private EduChapterService chapterService ;
    @ApiOperation("课程大纲列表，根据课程id进行查询")
    @GetMapping("getChapterList/{courseId}")
    public R addCourseInfo(@PathVariable String courseId){
//        课程大纲列表，根据课程id进行查询
        List<ChapterVo> list= chapterService.getChapterByCourseId(courseId) ;
        return R.ok().data("item",list) ;
    }
    @ApiOperation("添加章节")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        chapterService.save(eduChapter);
        return R.ok() ;
    }
    @ApiOperation("修改章节")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        chapterService.updateById(eduChapter);
        return R.ok() ;
    }
    @ApiOperation("根据id查询章节")
    @GetMapping("getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId){
        EduChapter eduChapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",eduChapter) ;
    }
    @ApiOperation("删除章节")
    @DeleteMapping("{chapterId}")
    public R deleteChapter(@PathVariable String chapterId){
        boolean flag = chapterService.deleteChapter(chapterId);
        return flag?R.ok():R.error();
    }


}

